package com.yuedao.sender.service1;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import cn.ydx.protobuf.OTIpcDef;

import com.yuedao.sender.model.BaseInfoCompany;
import com.yuedao.sender.model.BaseInfoCompanyFare;
import com.yuedao.sender.model.BaseInfoCompanyPay;
import com.yuedao.sender.model.BaseInfoCompanyPermit;
import com.yuedao.sender.model.BaseInfoCompanyService;
import com.yuedao.sender.model.BaseInfoCompanyStat;
import com.yuedao.sender.model.BaseInfoDriver;
import com.yuedao.sender.model.BaseInfoDriverApp;
import com.yuedao.sender.model.BaseInfoDriverEducate;
import com.yuedao.sender.model.BaseInfoDriverStat;
import com.yuedao.sender.model.BaseInfoPassenger;
import com.yuedao.sender.model.BaseInfoVehicle;
import com.yuedao.sender.model.BaseInfoVehicleInsurance;
import com.yuedao.sender.model.BaseInfoVehicleTotalMile;

@Service
public class BaseinfoService extends BaseService {

	@Value("${target.baseinfocompany.url}")
	private String companyURL;

	@Value("${target.baseinfocompanystat.url}")
	private String companyStatURL;

	@Value("${target.baseinfocompanypay.url}")
	private String companyPayURL;

	@Value("${target.baseinfocompanyservice.url}")
	private String companyServiceURL;

	@Value("${target.baseinfocompanypermit.url}")
	private String companyPermitURL;

	@Value("${target.baseinfocompanyfare.url}")
	private String companyFareURL;

	@Value("${target.baseinfovehicle.url}")
	private String vehicleURL;

	@Value("${target.baseinfovehicleinsurance.url}")
	private String vehicleInsuranceURL;

	@Value("${target.baseinfovehicletotalmile.url}")
	private String vehicleTotalMileURL;

	@Value("${target.baseinfodriver.url}")
	private String driverURL;

	@Value("${target.baseinfodrivereducate.url}")
	private String driverEducateURL;

	@Value("${target.baseinfodriverapp.url}")
	private String driverAppURL;

	@Value("${target.baseinfodriverstat.url}")
	private String driverStatURL;

	private String passengerURL = "/baseinfo/passenger";

	/**
	 * 网约车平台公司基本信息借口
	 */
	public String sendBaseInfoCompany(List<BaseInfoCompany> list ) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoCompany);
			for (BaseInfoCompany data : list) {
				builder.addBaseInfoCompany(BaseInfoCompany.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(companyURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.2 网约车平台公司营运规模信息接口
	 */
	public String sendBaseInfoCompanyStat(List<BaseInfoCompanyStat> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoCompanyStat);
			for (BaseInfoCompanyStat data : list) {
				builder.addBaseInfoCompanyStat(BaseInfoCompanyStat
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(companyStatURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.3 网约车平台公司支付信息接口
	 */
	public String sendBaseInfoCompanyPay(List<BaseInfoCompanyPay> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoCompanyPay);
			for (BaseInfoCompanyPay data : list) {
				builder.addBaseInfoCompanyPay(BaseInfoCompanyPay.convert(data));
			}

			/* logger.info(builder.toString()); */
			OTIpcDef.OTIpc otIpc = builder.build();
			System.out.println(companyPayURL);
			// logger.info(otIpc.toString());
			return super.compressAndSend(companyPayURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.4 网约车平台公司服务机构接口
	 */
	public String sendBaseInfoCompanyService(List<BaseInfoCompanyService> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoCompanyService);
			for (BaseInfoCompanyService data : list) {
				builder.addBaseInfoCompanyService(BaseInfoCompanyService
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(companyServiceURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.5 网约车平台公司经营许可接口
	 */
	public String sendBaseInfoCompanyPermit(List<BaseInfoCompanyPermit> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoCompanyPermit);
			for (BaseInfoCompanyPermit data : list) {
				builder.addBaseInfoCompanyPermit(BaseInfoCompanyPermit
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(companyPermitURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.6 网约车平台公司运价信息接口
	 */
	public String sendBaseInfoCompanyFare(List<BaseInfoCompanyFare> list ) {
		
		System.out.println("运价信息查询结果！" + list.size());
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoCompanyFare);
			for (BaseInfoCompanyFare data : list) {
				builder.addBaseInfoCompanyFare(BaseInfoCompanyFare
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(companyFareURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.7 车辆基本信息接口
	 */
	public String sendBaseInfoVehicle(List<BaseInfoVehicle> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoVehicle);
			for (BaseInfoVehicle data : list) {
				builder.addBaseInfoVehicle(BaseInfoVehicle.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(vehicleURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.8 车辆保险信息接口
	 */
	public String sendBaseInfoVehicleInsurance(	List<BaseInfoVehicleInsurance> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoVehicleInsurance);
			for (BaseInfoVehicleInsurance data : list) {
				builder.addBaseInfoVehicleInsurance(BaseInfoVehicleInsurance
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(vehicleInsuranceURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.9 网约车车辆里程信息接口
	 */
	public String sendBaseInfoVehicleTotalMile(List<BaseInfoVehicleTotalMile> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoVehicleTotalMile);
			for (BaseInfoVehicleTotalMile data : list) {
				builder.addBaseInfoVehicleTotalMile(BaseInfoVehicleTotalMile
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(vehicleTotalMileURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.10 驾驶员基本信息接口
	 */
	public String sendBaseInfoDriver(List<BaseInfoDriver> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoDriver);
			for (BaseInfoDriver data : list) {
				builder.addBaseInfoDriver(BaseInfoDriver.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(driverURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.11 网约车驾驶员培训信息接口
	 */
	public String sendBaseInfoDriverEducate(List<BaseInfoDriverEducate> list) {
	
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoDriverEducate);
			for (BaseInfoDriverEducate data : list) {
				builder.addBaseInfoDriverEducate(BaseInfoDriverEducate
						.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(driverEducateURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.12 驾驶员移动终端信息接口
	 */
	public String sendBaseInfoDriverApp(List<BaseInfoDriverApp> list ) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoDriverApp);
			for (BaseInfoDriverApp data : list) {
				builder.addBaseInfoDriverApp(BaseInfoDriverApp.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(driverAppURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.13 驾驶员统计信息接口
	 */
	public String sendBaseInfoDriverStat(List<BaseInfoDriverStat> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoDriverStat);
			for (BaseInfoDriverStat data : list) {
				builder.addBaseInfoDriverStat(BaseInfoDriverStat.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(driverStatURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.4.14 乘客基本信息接口
	 */
	public String sendBaseInfoPassenger(List<BaseInfoPassenger> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.baseInfoPassenger);
			for (BaseInfoPassenger data : list) {
				builder.addBaseInfoPassenger(BaseInfoPassenger.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(passengerURL, otIpc);
		}
		return "error";
	}

}
